

import requests
import json

if  __name__ == '__main__':
    url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
    # UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.76'
    }

    # kw = input('请输入城市：')
    kw_lists = {'长春', '上海', '北京', '广州', '深圳',

}
    for kw_list in kw_lists:
        print(kw_list)
        # for city['i'] in range(0,6):
        data = {
        'cname':'',
        'pid':'',
        'keyword': kw_list,
        # 外接关键字时不需要带’‘，注意
        'pageIndex': '1',
        'pageSize': '10',
        }


        response = requests.post(url=url,headers=headers,params = data)
        list_data = response.json()
        for item in list_data['Table1']:
            print(item['provinceName']+item['cityName']+item['addressDetail'])
            # +',' + item['pro']



        # print(list_data)
        # 测试数据
        fileName = kw_list+'.json'
        # 重命名名字
        fp = open(fileName,'w',encoding='utf-8')
        json.dump(list_data,fp = fp,ensure_ascii=False)
        print('over')
